namespace SimpleWebServices.Web.UI.Html.Elements
{
    using System.Xml.Serialization;
    using SimpleWebServices;
    using Xunit;

    public sealed class CellFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<Cell>()
                .DerivesFrom<CellAlignment>()
                .IsAbstractBaseClass()
                .Result);
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new TestCell() as Cell);
        }

        [Fact]
        public void prop_Abbreviated()
        {
            Assert.True(new PropertyExpectations(typeof(TestCell).GetProperty("Abbreviated"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_Axis()
        {
            Assert.True(new PropertyExpectations(typeof(TestCell).GetProperty("Axis"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_ColumnSpan()
        {
            Assert.True(new PropertyExpectations(typeof(TestCell).GetProperty("ColumnSpan"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_RowSpan()
        {
            Assert.True(new PropertyExpectations(typeof(TestCell).GetProperty("RowSpan"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void op_Deserialize_string_string_string()
        {
            Cell expected = new TestCell
            {
                Id = "id",
                Class = "class",
                Language = "fr",
                Title = "title",
                Alignment = "left",
                Character = "x",
                CharacterOffset = "2",
                VerticalAlignment = "middle",
                Abbreviated = "abbreviation",
                Axis = "location",
                ColumnSpan = "1",
                RowSpan = "1"
            };

            string xml =
                "<test" +
                " id='id'" +
                " class='class'" +
                " lang='fr'" +
                " title='title'" +
                " align='left'" +
                " char='x'" +
                " charoff='2'" +
                " valign='middle'" +
                " abbr='abbreviation'" +
                " axis='location'" +
                " colspan='1'" +
                " rowspan='1'" +
                "/>";
            Cell actual = new TestCell().Deserialize("test", null, xml) as Cell;

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }
    }
}